package it.evento.utils.genpage;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Ilo
 */
public class ArticleRow {
    
    private String content;
    private List<RowCell> cells;

    public ArticleRow() {
        resetAll();
    }

    public ArticleRow setContent(String content) {
        this.content = content;
        return this;
    }

    public ArticleRow setCells(List<RowCell> cells) {
        this.cells = cells;
        return this;
    }
    public ArticleRow setCells(RowCell[] cells) {
        List<RowCell> list = new LinkedList<>();
        list.addAll(Arrays.asList(cells));
        return setCells(list);
    }
    
    public String print() {
        String ret = "";
        
        ret += "<div class='evento-content-layout-wrapper layout-item-0'>";
            ret += "<div class='evento-content-layout layout-item-1'>";
                ret += "<div class='evento-content-layout-row'>";
                    if(!this.content.equals("") && !this.cells.isEmpty()) {
                        ret += this.content;
                        for(RowCell cell : this.cells) {
                            ret += cell.print();
                        }
                    }
                    else if(this.content.equals("")) {
                        for(RowCell cell : this.cells) {
                            ret += cell.print();
                        }
                    }
                    else if(this.cells.isEmpty()) {
                        ret += this.content;
                    }
                    else {
                        ret += "";
                    }
                ret += "</div>";
            ret += "</div>";
        ret += "</div>";
        
        resetAll();
        
        return ret;
    }
    
    private void resetAll() {
        this.content = "";
        this.cells = new LinkedList<>();
    }
    
}
